#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>


//  int mkfifo(const char *pathname, mode_t mode);

int main(){

	char buf[128]={0};
	int n_read = 0;

	if((mkfifo("./file",0600) == -1) && errno != EEXIST){
	
		printf("mkfifo failed!\n");
		perror("why");
	}

	int fd = open("./file",O_RDONLY);
	if(fd < 0){
		
		printf("open error!\n");
	}

	if(fd > 0){
		while(1){
			sleep(1);	
			n_read = read(fd,buf,128);
			printf("read %d byte from FIFO\ncontent is\"%s\"\n",n_read,buf);	
		}
	}
	close(fd);
	return 0;
}
